package servlet;

import utils.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@WebServlet(name = "DelateStudentServlet", value = "/DelateStudentServlet")
public class DelateStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        /**
         * 删除学生操作
         */
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=UTF-8");
        String sql = "delete from student where id=?";
        String id = request.getParameter("id");
        try {
            PreparedStatement ps = JDBCUtils.getconnection().prepareStatement(sql);
            ps.setString(1, id);
            int sout = ps.executeUpdate();
            System.out.println("updatesout = " + sout);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        request.getRequestDispatcher("all.jsp").forward(request, response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request, response);
    }
}
